package com.ycp.erp.role.ui.binder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.manager.event.BusManager;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.role.model.bean.Role;
import com.ycp.erp.role.model.event.RoleEvent;

import androidx.annotation.NonNull;

/**
 * Class Des:
 * Created by bjh on 2021/9/14.
 */
public class SelectRoleBinder extends BaseItemBinder<Role> {

    private final BaseActivity activity;

    public SelectRoleBinder(BaseActivity activity) {
        super(R.layout.item_role_select);
        this.activity=activity;
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, @NonNull Role item) {
        TextView tvCircleName = holder.getView(R.id.tvCircleName);
        TextView tvName = holder.getView(R.id.tvName);
        TextView tvNo = holder.getView(R.id.tvNo);
        tvCircleName.setText(item.getFirstName());
        tvName.setText(item.getName());
        tvNo.setText("ROLE_STAFF_"+item.getRolePhone());
        ImageView ivSelect = holder.getView(R.id.ivSelect);
        View rlItem = holder.getView(R.id.rlItem);
        if (item.isSelect()) {
            ivSelect.setImageResource(R.mipmap.ic_selected_circle);
        } else {
            ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
        }
        rlItem.setOnClickListener(v -> {
            item.setSelect(!item.isSelect());
            if (item.isSelect()) {
                ivSelect.setImageResource(R.mipmap.ic_selected_circle);
                BusManager.getBus().post(new RoleEvent(item));
                activity.finishPage();
            } else {
                ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
            }
        });
    }
}
